<template>
  <div class="wrap">
    <div class="page-head">
      <a-breadcrumb>
        <a-breadcrumb-item>{{ $t('whiteList.whiteList.60zenfbn7r40') }}</a-breadcrumb-item>
        <a-breadcrumb-item>{{ $t('droneModel.droneModel.60zeeomgv3o0') }}</a-breadcrumb-item>
      </a-breadcrumb>
    </div>
    <c-table-search :loading="form.loading" v-model:model="form.data" @refresh="getData">
      <a-col :span="8">
        <a-form-item field="keywords" :label="$t('device.device.60zedd3f1sg3')">
          <a-input v-model="form.data.keywords" :placeholder="$t('device.device.60zedd3f1sg4')" />
        </a-form-item>
      </a-col>
      <template v-slot:refresh>
        <a-button type="outline" @click="refresh">
          <template #icon>
            <icon-loop />
          </template>
        </a-button>
      </template>
      <template v-slot:addEquipment>
        <a-button type="primary" v-permission="['droneModel:add']" @click="form.create.show = true">
          <template #icon>
            <icon-plus />
          </template>
          {{ $t('droneModel.droneModel.60zeeomgxe81') }}
        </a-button>
      </template>
    </c-table-search>
    <div class="table-scroll">
      <c-table :list="form.list" :loading="form.loading" :count="form.count" v-model:data="form.data"
        @refresh="getData">
        <a-table-column :title="$t('droneModel.droneModel.60zeeomgv3o1')" ellipsis tooltip :width="120">
          <template #cell="{ rowIndex }">
            {{ rowIndex + 1 }}
          </template>
        </a-table-column>
        <a-table-column :title="$t('droneModel.droneModel.60zeeomgv3o2')" ellipsis tooltip :width="340">
          <template #cell="{ record }">
            {{ record.factory ? record.factory : '-' }}
          </template>
        </a-table-column>
        <a-table-column :title="$t('droneModel.droneModel.60zeeomgv3o3')" ellipsis tooltip :width="380">
          <template #cell="{ record }">
            {{ record.model ? record.model : '-' }}
          </template>
        </a-table-column>
        <a-table-column :title="$t('droneModel.droneModel.60zeeomgv3o4')" ellipsis tooltip :width="450">
          <template #cell="{ record }">
            {{ (`${record.factoryIndex}${record.modelIndex}`) ? (`${record.factoryIndex}${record.modelIndex}`) : '-' }}
          </template>
        </a-table-column>
        <a-table-column :title="$t('droneModel.droneModel.60zeeomgx400')" fixed='right' :width="180">
          <template #cell="{ record }">
            <a-space>
              <a-button type="text" v-permission="['droneModel:edit']"
                @click="handleUpdata(record)">{{ $t('droneModel.droneModel.60zeeomgx9s0') }}</a-button>
              <!-- <a-button type="text" v-permission="['droneModel:del']" status="danger"
                @click="handleDelete(record)">{{$t('droneModel.droneModel.60zeeomgxe80')}}</a-button> -->
            </a-space>
          </template>
        </a-table-column>
      </c-table>
      <Create @refresh="getData" v-model:show="form.create.show"></Create>
      <Updata @refresh="getData" v-model:show="form.update.show" v-model:data="form.update.data"></Updata>
    </div>
  </div>
</template>

<script lang='ts' setup>
import { apispectOperatorList } from '@/api/visual'
const Create = defineAsyncComponent(() => import('./components/create.vue'))
const Updata = defineAsyncComponent(() => import('./components/updata.vue'))
const temp = useTemp()
const local = useLocal()
const emit = defineEmits(['refresh'])
const refresh = () => {
  emit('refresh')
}
const form = reactive({
  create: {
    show: false
  },
  update: {
    loading: false,
    show: false,
    data: {},
  },
  delete: {
    show: false
  },
  // auths:[],
  // allAuths:[],
  data: {
    keywords: '',
    page: 1,
    pageSize: 20,
    uid: local.usermsg.id == 3 ? 0 : local.usermsg.id
  },
  loading: false,
  list: [],
  count: 0
})
// 无人机运营商列表
const getData = async () => {
  form.loading = true
  const { code, data } = await apispectOperatorList({
    ...form.data,
  })
  form.loading = false
  if (code != 200) return;
  form.list = data.list
  form.count = data.total
}
// 编辑
const handleUpdata = (record: any) => {
  form.update.data = cloneDeep(record)
  form.update.show = true
}
// 删除
// const handleDelete = async (record: any) => {
//   useModal.warning({
//     content: t('device.device.60zedd3f1sg0'),
//     onBeforeOk: async () => {
//       const { code } = await apiDeviceDelete({
//         id: record.id
//       })
//       if (code != 200) return false;
//       useMessage.success()
//       getData()
//       return true
//     }
//   })
// }
onBeforeMount(() => {
  getData()
  temp.getDeviceGroupList()
})
</script>

<style scoped lang="less">
.show {
  display: none
}

.color {
  width: 30px;
  height: 30px;
  border-radius: 2px;
}
</style>
